"""
系统部署页
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from pages.base_page import BasePage

class SystemSetPage(BasePage):
    systemname_locator = (By.ID, "name")
    systemdescribe_locator = (By.ID, "description")
    logo_locator = (By.NAME, "logo")
    region_province_locator = (By.ID, "state")
    region_city_locator = (By.ID, "city")
    uploadfile_locator = (By.NAME, "allow_file_type")
    open_locator = (By.ID, "opendebug") # 打开调测模式
    close_locator = (By.ID, "closedebug") # 关闭调测模式
    contract_alert_time_locator = (By.NAME, "contract_alert_time") # 合同提醒时间
    contract_custom_locator = (By.NAME, "contract_custom")         # 合同前缀
    customer_outdays_locator = (By.NAME, "customer_outdays")       # 客户池回收周期
    customer_limit_condition_locator = (By.NAME, "customer_limit_condition")  # 客户领取周期内
    customer_limit_counts_locator = (By.NAME, "customer_limit_counts")  # 客户领取周期次数
    leads_outdays_locator = (By.NAME, "leads_outdays")  # 线索回收周期
    submit_locator = (By.NAME, "submit")  # 点击保存
    save_succeed_locator = (By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")


    # 清理系统名称
    def clear_system_name(self):
        self.driver.find_element(*self.systemname_locator).clear()
    # 清理系统描述
    def clear_system_describe(self):
        self.driver.find_element(*self.systemdescribe_locator).clear()
    # 清理允许上传文件类型
    def clear_allow_upload_file_type(self):
        self.driver.find_element(*self.uploadfile_locator).clear()
    # 清理合同提醒时间
    def clear_contract_alert_time(self):
        self.driver.find_element(*self.contract_alert_time_locator).clear()
    # 清理设置合同前缀
    def clear_set_contract_prefix(self):
        self.driver.find_element(*self.contract_custom_locator).clear()
    # 清理客户池回收周期
    def clear_client_recycle_period(self):
        self.driver.find_element(*self.customer_outdays_locator).clear()
    # 清理客户领取限制次数
    def clear_client_get_number(self):
        self.driver.find_element(*self.customer_limit_counts_locator).clear()
    # 清理线索池回收周期
    def clear_club_recycle_period(self):
        self.driver.find_element(*self.leads_outdays_locator).clear()

    # 点击输入系统名称
    def system_name(self,systemname):
        self.driver.find_element(*self.systemname_locator).send_keys(systemname)
    # 点击输入系统描述
    def system_describe(self,systemdescribe):
        self.driver.find_element(*self.systemdescribe_locator).send_keys(systemdescribe)
    # 点击选择系统logo
    def select_file(self,xiaoheizi):
        self.driver.find_element(*self.logo_locator).send_keys(xiaoheizi)
    # 点击选择默认地区省份
    def region_province(self,text):
        province_element = self.driver.find_element(*self.region_province_locator)
        region = Select(province_element)
        region.select_by_visible_text(text)
    # 点击选择默认地区城市
    def region_city(self,text):
        city_element = self.driver.find_element(*self.region_city_locator)
        region = Select(city_element)
        region.select_by_visible_text(text)
    # 点击输入允许上传的文件类型
    def allow_upload_file_type(self,filetype):
        self.driver.find_element(*self.uploadfile_locator).send_keys(filetype)
    # 打开调测模式
    def open_pattern(self):
        self.driver.find_element(*self.open_locator).click()
    # 关闭调测模式
    def close_pattern(self):
        self.driver.find_element(*self.close_locator).click()
    # 弹窗确认框
    def confirm(self):
        self.driver.switch_to.alert.accept()
    # 点击输入合同提醒时间
    def contract_alert_time(self,contract_alert_time):
        self.driver.find_element(*self.contract_alert_time_locator).send_keys(contract_alert_time)
    # 点击输入设置合同前缀
    def set_contract_prefix(self,set_contract_prefix):
        self.driver.find_element(*self.contract_custom_locator).send_keys(set_contract_prefix)
    # 点击输入客户池回收周期
    def client_recycle_period(self,client_recycle_period):
        self.driver.find_element(*self.customer_outdays_locator).send_keys(client_recycle_period)
    # 点击输入客户的领取周期
    def client_get_period(self,text):
        customer_limit_condition_element = self.driver.find_element(*self.customer_limit_condition_locator)
        period = Select(customer_limit_condition_element)
        period.select_by_visible_text(text)
    # 点击输入客户领取次数限制
    def client_get_number(self,client_get_number):
        self.driver.find_element(*self.customer_limit_counts_locator).send_keys(client_get_number)
    # 点击输入线索回收周期
    def club_recycle_period(self,club_recycle_period):
        self.driver.find_element(*self.leads_outdays_locator).send_keys(club_recycle_period)
    # 点击保存按钮
    def sava(self):
        self.driver.find_element(*self.submit_locator).click()
    # 设置成功并保存（文本）
    def sava_succeed(self):
        return self.driver.find_element(*self.save_succeed_locator).text
